using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;

/****************************************************
// 功能：许可协议界面
// | Talk To [ 聊来改善地区金融服务环境，助力企业发展 ]
// | Copyright (c) 2021-2025 聊来 All rights reserved.
// | Licensed ( <a href="http://www.apache.org/licenses/LICENSE-2.0">聊来</a> )
// | @Author: 贯彻己道的云 <18970881148@qq.com>
// | DateTime: 2024/12/31 15:47:16
*****************************************************/

public class ProtocolWindow : BaseWindow, IPointerClickHandler
{
    private TMP_Text text;

    private void Awake()
    {
        text = FindChildTransform(transform, "click").GetComponent<TMP_Text>();
    }

    // Start is called before the first frame update
    void Start()
    {
    }

    // Update is called once per frame
    void Update()
    {
    }

    protected override void OnOpen(object arg)
    {
        base.OnOpen(arg);
        SetText(text, arg as string);
    }

    /// <summary>
    /// 拒绝
    /// </summary>
    public void TurnClickButton()
    {
        UIManager.Instance.PopUp(WindowName.AlertNormal, null);
    }

    /// <summary>
    /// 同意
    /// </summary>
    public void AgreeClickButton()
    {
        audioManager.PlayUIAudio(Constants.UI_CLICK_BTN);
        SetWindowsState(WindowName.Protocol, false);
    }

    public void OnPointerClick(PointerEventData eventData)
    {
        int index = TMP_TextUtilities.FindIntersectingLink(text, eventData.position, null);
        if (index != -1)
        {
            TMP_LinkInfo linkInfo = text.textInfo.linkInfo[index];
            Application.OpenURL(linkInfo.GetLinkID());
        }
    }
}